home *** CD-ROM | disk | FTP | other *** search
/ CICA 1997 August / CICA - The Ultimate Collection of Shareware for Windows (Walnut Creek) (August 1997) (Disc 1).iso / utils / unix / unzip520 / wingui / winsetup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-29  |  5.4 KB  |  188 lines

  1. /* MS Windows Setup  and Take-Down functions bracket calls to
  2.  * process_zipfiles().
  3.  * These functions allocate and free the necessary buffers, set and clear
  4.  * any global variables so that  process_zipfiles()  can be called multiple
  5.  * times in the same session of WizUnzip. You'll recognize some of the
  6.  * code from main() in SetUpToProcessZipFile().
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <windows.h>
  11. #include "version.h"
  12. #include "wingui\wizunzip.h"
  13. #define UNZIP_INTERNAL
  14. #include "unzip.h"
  15. #include "consts.h"
  16.  
  17. #ifndef USEWIZUNZDLL
  18. static long ziplen;
  19. static uch *outout;
  20. #endif /* USEWIZUNZDLL */
  21.  
  22. HANDLE hOutBuf;
  23. HANDLE hInBuf;
  24. HANDLE hZipFN;
  25. HANDLE hwildZipFN;
  26. HANDLE hFileName;
  27.  
  28. /*
  29.     ncflag    = write to stdout if true
  30.     ntflag    = test zip file
  31.     nvflag    = verbose listing
  32.     nUflag    = "update" (extract only newer/new files
  33.     nzflag    = display zip file comment
  34.     ndflag    = all args are files/dir to be extracted
  35.     noflag    =
  36.     naflag    = do ASCII-EBCDIC and/or end of line translation
  37.     argc      =
  38.     lpszZipFN = zip file name
  39.     FNV       = file name vector to list of files to extract
  40. */
  41. #ifndef USEWIZUNZDLL
  42. BOOL FSetUpToProcessZipFile(LPDCL C)
  43. {
  44.     /* clear all global flags -- need to or not. */
  45.     G.tflag=G.vflag=G.cflag=G.aflag=G.uflag=G.qflag=G.zflag=0;
  46.     G.overwrite_all=G.overwrite_none=0;
  47.     G.pfnames = &fnames[0];       /* assign default file name vector */
  48.  
  49.     G.jflag = !C->ndflag; /* WizUnZip perspective is "recreate dir structure" */
  50.     G.cflag = C->ncflag ;
  51.     G.overwrite_all = C->noflag;
  52.     G.tflag = C->ntflag ;
  53.     G.vflag = C->nvflag;
  54.     G.zflag = C->nzflag;
  55.     G.uflag = C->nUflag;
  56.     G.aflag = C->naflag;
  57.     G.uflag = C->ExtractOnlyNewer;
  58.     if (C->Overwrite) {
  59.         G.overwrite_all = TRUE;
  60.         G.overwrite_none = FALSE;
  61.     } else {
  62.         G.overwrite_all = FALSE;
  63.         G.overwrite_none = TRUE;
  64.     }
  65.     G.sflag = C->SpaceToUnderscore; /* Translate spaces to underscores? */
  66.  
  67.     G.filespecs = C->argc;
  68.     G.xfilespecs = 0;
  69.  
  70.     G.local_hdr_sig[0] = G.central_hdr_sig[0] = G.end_central_sig[0] = '\120';
  71.     G.local_hdr_sig[1] = G.central_hdr_sig[1] = G.end_central_sig[1] = '\0';
  72.  
  73.     G.cur_zipfile_bufstart = 0L;
  74.     if ((hZipFN = GlobalAlloc(GMEM_MOVEABLE, FILNAMSIZ))== NULL)
  75.         return FALSE;
  76.  
  77.     G.zipfn = (char far *)GlobalLock(hZipFN);
  78.     lstrcpy(G.zipfn, C->lpszZipFN);
  79.  
  80. /* MW: G.wildzipfn needs to be initialized so that do_wild does not wind
  81.    up clearing out the zip file name when it returns in process.c
  82. */
  83.     if ((hwildZipFN = GlobalAlloc(GMEM_MOVEABLE, FILNAMSIZ))== NULL)
  84.         return FALSE;
  85.  
  86.     G.wildzipfn = GlobalLock(hwildZipFN);
  87.     lstrcpy(G.wildzipfn, C->lpszZipFN);
  88.  
  89.     if (stat(G.zipfn, &G.statbuf) || (G.statbuf.st_mode & S_IFMT) == S_IFDIR)
  90.         strcat(G.zipfn, ZSUFX);
  91.  
  92.     if (stat(G.zipfn, &G.statbuf)) {  /* try again */
  93.         fprintf(stdout, "error:  can't find zipfile [ %s ]\n", G.zipfn);
  94.         return FALSE;
  95.     } else
  96.         ziplen = G.statbuf.st_size;
  97.  
  98.     if (C->argc != 0) {
  99.         G.pfnames = C->FNV;
  100.         G.process_all_files = FALSE;
  101.     } else
  102.         G.process_all_files = TRUE;       /* for speed */
  103.  
  104. /*---------------------------------------------------------------------------
  105.     Okey dokey, we have everything we need to get started.  Let's roll.
  106.   ---------------------------------------------------------------------------*/
  107.  
  108.     if ((hInBuf = GlobalAlloc(GMEM_MOVEABLE, INBUFSIZ+4)) != NULL) {
  109.         G.inbuf = (uch *) GlobalLock(hInBuf);
  110.         WinAssert(G.inbuf);
  111.     }
  112.     if ((hOutBuf = GlobalAlloc(GMEM_MOVEABLE, OUTBUFSIZ+1)) != NULL) {
  113.         G.outbuf = (uch *)GlobalLock(hOutBuf);
  114.         WinAssert(G.outbuf);
  115.         outout = G.outbuf;  /*  point to outbuf */
  116.     }
  117.     if ((hFileName = GlobalAlloc(GMEM_MOVEABLE, FILNAMSIZ)) != 0) {
  118.         G.filename = GlobalLock(hFileName);
  119.         WinAssert(G.filename);
  120.     }
  121.  
  122.     if ((G.inbuf == NULL) || (G.outbuf == NULL) || (outout == NULL) ||
  123.         (G.zipfn == NULL) || (G.filename == NULL))
  124.         return FALSE;
  125.  
  126.     G.hold = &G.inbuf[INBUFSIZ]; /* to check for boundary-spanning signatures */
  127.  
  128.     return TRUE;    /* set up was OK */
  129. }
  130.  
  131. void TakeDownFromProcessZipFile(void)
  132. {
  133.     if (G.inbuf) {
  134.         GlobalUnlock(hInBuf);
  135.         G.inbuf = NULL;
  136.     }
  137.     if (hInBuf)
  138.         hInBuf = GlobalFree(hInBuf);
  139.  
  140.     if (G.outbuf) {
  141.         GlobalUnlock(hOutBuf);
  142.         G.outbuf = NULL;
  143.     }
  144.     if (hOutBuf)
  145.         hOutBuf = GlobalFree(hOutBuf);
  146.  
  147.     if (G.zipfn) {
  148.         GlobalUnlock(hZipFN);
  149.         G.zipfn = NULL;
  150.     }
  151.     if (hZipFN)
  152.         hZipFN = GlobalFree(hZipFN);
  153.  
  154.     if (G.wildzipfn) {
  155.         GlobalUnlock(hwildZipFN);
  156.         G.wildzipfn = NULL;
  157.     }
  158.     if (hwildZipFN)
  159.         hwildZipFN = GlobalFree(hwildZipFN);
  160.  
  161.     if (G.filename) {
  162.         GlobalUnlock(hFileName);
  163.         G.filename = NULL;
  164.     }
  165.     if (hFileName)
  166.         hFileName = GlobalFree(hFileName);
  167. }
  168.  
  169. int GetReplaceDlgRetVal(void)
  170. {
  171.     FARPROC lpfnprocReplace;
  172.     int ReplaceDlgRetVal;   /* replace dialog return value */
  173.  
  174.     ShowCursor(FALSE);      /* turn off cursor */
  175.     SetCursor(hSaveCursor); /* restore the cursor */
  176.     lpfnprocReplace = MakeProcInstance(ReplaceProc, hInst);
  177.     ReplaceDlgRetVal = DialogBoxParam(hInst, "Replace",
  178.       hWndMain, lpfnprocReplace, (DWORD)(LPSTR)G.filename);
  179. #ifndef WIN32
  180.     FreeProcInstance(lpfnprocReplace);
  181. #endif
  182.     hSaveCursor = SetCursor(hHourGlass);
  183.     ShowCursor(TRUE);
  184.     return ReplaceDlgRetVal;
  185. }
  186.  
  187. #endif /* USEWIZUNZDLL */
  188.